package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.control.toast.MoHuToast;
import com.wgts.wgts.mvp.model.ICollectActivityModel;
import com.wgts.wgts.mvp.model.IJDGoodInfoActivityModel;
import com.wgts.wgts.mvp.presenter.ICollectActivityPresenter;
import com.wgts.wgts.mvp.view.ICollectActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.CollectListEntity;
import com.wgts.wgts.netmodle.resp.CurrentEntity;

import java.util.ArrayList;
import java.util.List;

/*
 *
 *
 *   data:2018/10/79:24
 *
 */public class CollectActivityPresenter implements ICollectActivityPresenter {
     private ICollectActivityView view;
     private ICollectActivityModel model;
     private Integer count;
     private List<CollectListEntity.List> lists = new ArrayList<>();
     private String deleteCollects;


    public CollectActivityPresenter(ICollectActivityView view, ICollectActivityModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void collectList(Integer pageIndex, Integer pageSize) {
        model.collectList(pageIndex, pageSize, new HttpResultSubscriber<CollectListEntity>() {
            @Override
            public void onSuccess(CollectListEntity collectListEntity) {
                count = collectListEntity.count;
                lists = collectListEntity.list;
                view.collectList(lists);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }


    @Override
    public void deleteCollect(String productIds) {
        model.deleteCollect(productIds, new HttpResultSubscriber<CurrentEntity>() {
            @Override
            public void onSuccess(CurrentEntity currentEntity) {
                view.deleteCollect();
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void haveLoseCollect() {
        deleteCollects = "";
        for (int i = 0; i < lists.size(); i++){
            if (!lists.get(i).status.equals("ACTIVE")){
                deleteCollects += lists.get(i).productId + ",";
            }
        }
        view.haveLoseCollect(deleteCollects);
    }

    @Override
    public void cancelCollect(int position) {
        model.deleteCollect(lists.get(position).productId, new HttpResultSubscriber<CurrentEntity>() {
            @Override
            public void onSuccess(CurrentEntity currentEntity) {
                view.deleteCollect();
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

}
